package com.handu.luna.core.domain.goods;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;

import com.handu.luna.core.domain.BasePersistentDomain;

@Entity
public class Attribute  extends BasePersistentDomain<AttributeRepository>{

	@Size(min=1,max=10, message="属性名称长度不能为空或超过10个字。")
	private String name;
	
	//可选类型，可选值为唯一、单选、多选。
	private SelectType selectType;
	
	
	public enum SelectType{
		ONLY("唯一属性"),SINGLE("单选属性");		
	    public String description;	    
	    SelectType(final String description) {
	        this.description = description;
	    }
	}
	
	//录入方式：手动、选择。
	/*private InputMode inputMode;
	
	public enum InputMode{
		MANUAL("手工录入"),SELECT("选择录入");		
	    public String description;	    
	    InputMode(final String description) {
	        this.description = description;
	    }
	}*/
	
	
	@Size(min=1,max=10000, message="属性值长度不能为空或超过10000个字。")
	private String inputValues;
	
	public List<String> getInputValueList(){
		String[] values = inputValues.split("\n");
		ArrayList<String> list = new ArrayList<String>();
		for(String value : values){
			list.add(value);
		}
		return list;
	}
	
	//排序
	@Min(value =0,message="取值范围:0~255,包含0,不包含255。")
	@Max(value =254,message="取值范围:0~255,包含0,不包含255。")
	private int attributeSort = 100;
	
	public Attribute(){}
	
	/**
	 * 
	 * @param name
	 * @param selectType
	 * @param inputMode
	 * @param inputValues
	 */
	public Attribute(String name, SelectType selectType, 
			String inputValues,int attributeSort) {
		super();
		this.name = name;
		this.selectType = selectType;
		this.inputValues = inputValues;
		this.attributeSort = attributeSort;
	}

	/**
	 * 
	 * @param name
	 * @param selectType
	 * @param inputMode
	 * @param inputValues
	 */
	public Attribute(SelectType selectType) {
		super();
		this.selectType = selectType;
	}



	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public SelectType getSelectType() {
		return selectType;
	}

	public void setSelectType(SelectType selectType) {
		this.selectType = selectType;
	}



	public String getInputValues() {
		return inputValues;
	}

	public void setInputValues(String inputValues) {
		this.inputValues = inputValues;
	}

	public int getAttributeSort() {
		return attributeSort;
	}

	public void setAttributeSort(int attributeSort) {
		this.attributeSort = attributeSort;
	}
	
	
	
	
	
	
	
}
